﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SalesSys.DAL.Base;

namespace SalesSys.DAL.Models
{
   /*
    * 在此定义财务相关内容实体
    * 财务内容：客户帐、户头、报款、退款
    */
   /// <summary>
   /// 财务流水
   /// </summary>
    public class Finance : DbEntityBase<Guid>
    {
        public Finance()
        {
            CreateTime = new DateTime();
        }
        /// <summary>
        /// 户头编号
        /// </summary>
        public virtual Account Account { get; set; }

        /// <summary>
        /// 金额
        /// </summary>
        public decimal Money { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 变动前
        /// </summary>
        public decimal BeforeAmount { get; set; }

        /// <summary>
        /// 变动后
        /// </summary>
        public decimal AfterAmount { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 关联人
        /// </summary>
        public virtual Employee Handler { get; set; }

        /// <summary>
        /// 描述标题
        /// </summary>
        public string SourceInfo { get; set; }

        /// <summary>
        /// 来源编号
        /// </summary>
        public string SourceTag { get; set; }
        public class Mapper : SalMapper<Finance, Guid>
        {
            public Mapper()
            {
 
            }
        }
    }

    /// <summary>
    /// 客户户头
    /// </summary>
    public class Account : TimestampEntity<Guid>
    {
        /// <summary>
        /// 客户
        /// </summary>
        public virtual Customer Customer { get; set; }

        /// <summary>
        /// 客户编号
        /// </summary>
        public Guid CustomerId { get; set; }

        /// <summary>
        /// 户头名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 账户余额
        /// </summary>
        public decimal Amount { get; set; }

        /// <summary>
        /// 是否私户
        /// </summary>
        public bool IsCash { get; set; }
        /// <summary>
        /// 银行名称
        /// </summary>
        public string BankName { get; set; }
        /// <summary>
        /// 银行卡号
        /// </summary>
        public string BankNumber { get; set; }
        /// <summary>
        /// 应收帐，所有结算后 应支付-已支付 的总和
        /// </summary>
        public decimal Receivables { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        public class Mapper : SalMapper<Account, Guid>
        {
            public Mapper()
            {
                HasRequired(p => p.Customer);
                Property(p => p.Name).HasMaxLength(50);
            }
        }
    }

    /// <summary>
    /// 报款管理
    /// </summary>
    public class PaymentInfo : DbEntityBase<Guid>
    {
        public class Mapper : SalMapper<PaymentInfo, Guid>
        {
            Mapper()
            {

                HasOptional(p => p.Customer);
                HasOptional(p => p.CustomerAgent);
                Property(p => p.Sum).IsRequired();
                Property(p => p.Type).IsRequired();
 
            }
        }

        /// <summary>
        /// 审批类型
        /// </summary>
        public FinaceApprovalState State { get; set; }

        /// <summary>
        /// 付款、退款
        /// </summary>
        public PaymentStatus PaymentStatus { get; set; }

        /// <summary>
        /// 客户
        /// </summary>
        public virtual Customer Customer { get; set; }

        /// <summary>
        /// 户头
        /// </summary>
        public virtual Account Account { get; set; }

        /// <summary>
        /// 户头编号
        /// </summary>
        public Guid AccountId { get; set; }

        /// <summary>
        /// 收款账户
        /// </summary>
        public string ToAccount { get; set; }

        /// <summary>
        /// 款项处理人
        /// </summary>
        public Employee Handler { get; set; }

        /// <summary>
        /// 金额
        /// </summary>
        public decimal Sum { get; set; }

        /// <summary>
        /// 银行信息
        /// </summary>
        public string Bank { get; set; }

        /// <summary>
        /// 货款、锁货款、预付款
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        
        /// <summary>
        /// 客户经理
        /// </summary>
        public virtual Employee CustomerAgent { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 报款时间
        /// </summary>
        public DateTime? PaymentTime { get; set; }

        /// <summary>
        /// 审批时间
        /// </summary>
        public DateTime? ApprovalTime { get; set; }

        /// <summary>
        /// 审批备注
        /// </summary>
        public string ApprovalRemark { get; set; }
    }
  
    public enum PaymentType
    {
        /// <summary>
        /// 货款
        /// </summary>
        [Description("货款")]
        Goods = 1,
        /// <summary>
        /// 锁货款
        /// </summary>
        [Description("锁货款")]
        Lock = 2,
        /// <summary>
        /// 预付款
        /// </summary>
        [Description("预付款")]
        Advance = 3
    }
}
